cd "/Users/TJRyan/Library/CloudStorage/Dropbox/2022 Primary Survey/POBE Replication files"

**# Figure 1. Electability by respondent
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

egen e_max = max(electability_), by(responseid)
egen e_min = min(electability_), by(responseid)
bysort responseid: gen ingroup = _n
keep if ingroup==1
gen e_dif = e_max - e_min
hist e_dif, bin(11) frac graphregion(color(white)) xtitle("Electability difference score") ytitle("Proportion")

**# Figure 2. Electability, by candidate and race
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

keep if controlcond==1 // Limit to respondents whose electability perceptions are not influenced by the experiment.
collapse (mean) electability_ (semean) se_elect=electability_ (firstnm) race_fe, by(cand_name)
encode race_fe, gen(race_fe2)

gen race_fe3 = . // Helpful to have a numeric version of this for plotting.
foreach num of numlist 1/9 {
	replace race_fe3 = `num' if race_fe2==`num'
	}

sort race_fe3
by race_fe3: generate ingroup = (_n - 1) // Candidate numbers within race.
replace race_fe3 = race_fe3 + .05 * ingroup // Create spacing along x-axis.
replace race_fe3 = race_fe3 - 1 // start at zero.

gen high = electability_ + 1.96*se_elect
gen low = electability_ - 1.96*se_elect

twoway (scatter electability_ race_fe3, mcolor(black) msize(vsmall) mlabel(cand_name) mlabangle(20) mlabcolor(edkblue)) ///
	(rspike low high race_fe3, lcolor(black)), ///
	legend(off) xtitle("") xoverhangs graphregion(color(white) margin(vlarge)) xsize(7) ysize(3) ///
	xlab(0 "NC_GOP_Sen" 1 "OH_Dem_Sen" 2 "OH_GOP_Gov" 3 "OH_GOP_Sen" 4 "PA_Dem_Sen" 5 "PA_GOP_Gov" 6 "PA_GOP_Sen" 7 "WI_Dem_Sen" 8 "WI_GOP_Gov", angle(30))		

	
**# Figure 3. Manipulation Check	
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

reg mc_moderate informed_moderate i.race_fe2, vce(cluster responseid)	
margins, at(race_fe2 = (1,2,3,4,5,6,7,8,9) informed_moderate = (0,1)) level(95)
mplotoffset, plot1opts(connect(none) msize(large) color(cranberry)) ci1opts(lcolor(cranberry)) ///
plot2opts(connect(none) msize(large) color(dkgreen)) ci2opts(lcolor(dkgreen)) ///
    xlab(, angle(30) labsize(small)) xoverhangs graphregion(color(white) margin(10 0 0 0)) ///
    xtitle("") ytitle("Proportion correct") title("Moderation") legend(off)
graph save "4_figures/mcfig_moderation.gph", replace

reg mc_money informed_money##i.race_fe2, vce(cluster responseid)
margins, at(race_fe2 = (1,2,3,4,5,6,7,8) informed_money = (0,1)) level(95)
mplotoffset, plot1opts(connect(none) msize(large) color(cranberry)) ci1opts(lcolor(cranberry)) ///
plot2opts(connect(none) msize(large) color(dkgreen)) ci2opts(lcolor(dkgreen)) ///
    xlab(, angle(30) labsize(small)) xoverhangs graphregion(color(white) margin(0 0 0 0)) ///
    xtitle("") ytitle("") title("Money") legend(off)
graph save "4_figures/mcfig_money.gph", replace

preserve
drop if race_fe2==1 | race_fe2==5 | race_fe2==7 // No experience treatment here
recode race_fe2 (2=1) (3=2) (4=3) (6=4) (8=5) (9=6)
reg mc_office informed_office##i.race_fe2, vce(cluster responseid)
margins, at(race_fe2 = (1,2,3,4,5,6) informed_office = (0,1)) level(95)
mplotoffset, plot1opts(connect(none) msize(large) color(cranberry)) ci1opts(lcolor(cranberry)) ///
plot2opts(connect(none) msize(large) color(dkgreen)) ci2opts(lcolor(dkgreen)) ///
    xlab(, angle(30) labsize(small)) xoverhangs graphregion(color(white) margin(0 0 0 0)) ///
    xtitle("") ytitle("") title("Experience") legend(off)
restore
graph save "4_figures/mcfig_experience.gph", replace

graph combine "4_figures/mcfig_moderation.gph" "4_figures/mcfig_money.gph" "4_figures/mcfig_experience.gph", cols(3) xsize(8) ysize(4) ycommon title("") imargin(10 0 0 0) graphregion(color(white))

graph play "addrefs.grec"

graph export "4_figures/manipcheck.png", width(2000) replace

**# Figure 4: Net Effects of Information on Perceived Electability
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

* Create variables that =1 when respondent saw *either* "yes" or "no" versions of the treatment. (Convenient for estimating and plotting yes-vs-no contrasts.)
gen moderation=t_moderate_y_+t_moderate_n_
gen moneytreatment=t_money_y_ +t_money_n_
gen exper=t_exp_y_ +t_exp_n_

reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe2, vce(cluster responseid)
estimates store A
	
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe2  if party==1, vce(cluster responseid)
estimates store B
	
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe2  if party==2, vce(cluster responseid)
estimates store C
	
coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)) ///
	(B, msymbol(D) ciopts(lcolor(blue)) color(blue)) ///
	(C, msymbol(T) ciopts(lcolor(red)) color(red)),  vertical ytitle( "Differences between the two" "treatments (more versus less)") keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising" 3 "Experience") legend(row(1) label(2 "All") label(4 "Democratic Primaries") label(6 "Republican Primaries")) graphregion(fcolor(white) ifcolor(white)) 
	
graph export "4_figures/diff.png", width(1000) replace

**# Table 1: News Coverage of Electability and Electability Considerations
use "2_workingdata/News Article Content.dta", clear

** Drop Observations that are not relevant
drop if primary==0

tab electability
tab ideology // Note: Based on codebook, 0 = not mentioned, 1 = minor point, 2 = major point
tab fundraising
tab experience


**# Table 2: Observational Predictors of Candidate Electability
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

reg electability  perceived_moderate_  perceived_money_ perceived_office_ i.race_fe2 if controlcond==1, vce(cluster responseid)
reg electability perceived_moderate_  perceived_money_ perceived_office_ i.race_fe2 if controlcond==1 & pure_ind==1, vce(cluster responseid)
reg electability perceived_moderate_  perceived_money_ perceived_office_ i.race_fe2 if controlcond==1 & leaner==1, vce(cluster responseid)
reg electability perceived_moderate_  perceived_money_ perceived_office_ i.race_fe2 if controlcond==1 & weak_partisan==1, vce(cluster responseid)
reg electability perceived_moderate_  perceived_money_ perceived_office_ i.race_fe2 if controlcond==1 & strong_partisan==1, vce(cluster responseid)

	
**# Table 3: Experimental Treatment Effects on Electability
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

** Pre-registered specification, all voters
reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ i.cand_name2, vce(cluster responseid)
	test t_moderate_y_ -t_moderate_n = 0 // Test equivalence of "more" and "less" treatments.
	test t_money_y_ -t_money_n = 0
	test t_exp_y_ -t_exp_n = 0

** Race FEs, all voters
reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2, vce(cluster responseid)
	test t_moderate_y_ -t_moderate_n = 0	
	test t_money_y_ -t_money_n = 0
	test t_exp_y_ -t_exp_n = 0
	
** Race FEs, Democrats
	reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==1, vce(cluster responseid)
	test t_moderate_y_ -t_moderate_n = 0	
	test t_money_y_ -t_money_n = 0
	test t_exp_y_ -t_exp_n = 0
	
** Race FEs, Republicans
	reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==2, vce(cluster responseid)
	test t_moderate_y_ -t_moderate_n = 0	
	test t_money_y_ -t_money_n = 0
	test t_exp_y_ -t_exp_n = 0

**# Table 4: Complier Average Treatment Effect
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0
	
** Candidate fixed effects (pre-registered)
xi: ivreg electability_ i.cand_name2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid) first
	
** All Voters, race FEs
xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid) first

** Democrats, race FEs
xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==1, cluster (responseid) first

** Republicans, race FEs
xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==2, cluster (responseid) first


**# Table 5: Informational Treatments ITT Effect on Vote Choice
** Candidate fixed effects (pre-registered)
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0
	
oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_   i.cand_name2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0 // Test equivalence of "more" and "less" treatments.
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0

** All Voters, race FEs
oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Democrats, race FEs
oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==1, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Republicans, race FEs
oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0

**# Sundry statistics reported in text
* Number of Republicans and Democrats (footnote 20)
preserve
bysort responseid: gen ingroup = _n
keep if ingroup==1
tab party
restore

**# Results in the Appendix
* Exclusions due to lateness. (SI Section 3)
use "2_workingdata/working_long.dta", clear
bysort responseid: gen ingroup = _n
keep if ingroup==1
tab late_response

**# Figure SI2: Sensitivity Analysis
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

gen moderation = t_moderate_y_ + t_moderate_n_ // Variables convenient for yes/no contrasts.
gen moneytreatment = t_money_y_ + t_money_n_
gen exper = t_exp_y_ + t_exp_n_

levelsof race_fe, local(clusters)

foreach cl in `clusters' {
	reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe!="`cl'", vce(cluster responseid)
	est store A
	
	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("Excluding `cl'", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising" 3 "Experience", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
	ysc(r(-2 6)) ylab(-2(2)6)
	
	graph save "4_figures/jack_`cl'.gph", replace
}

fs "4_figures/*jack_*.gph"

local all_graphs ""
foreach file in `r(files)' {
    local all_graphs `"`all_graphs' "4_figures/`file'" "'
}

graph combine `all_graphs', graphregion(color(white))
graph export "4_figures/fig_si2.png", width(1000) replace

**# Figure SI3: Race-by-race results
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

gen moderation = t_moderate_y_ + t_moderate_n_ // Variables convenient for yes/no contrasts.
gen moneytreatment = t_money_y_ + t_money_n_
gen exper = t_exp_y_ + t_exp_n_

levelsof race_fe, local(clusters)

foreach cl in `clusters' {
	reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe=="`cl'", vce(cluster responseid)
	est store A
	
	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("`cl'", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising" 3 "Experience", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
	ysc(r(-10 15)) ylab(-10(5)15, labsize(vsmall))
	
	graph save "4_figures/rbr_`cl'.gph", replace
}

* Cases that need special attention -- Wisconsin
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe=="WI_GOP_Governor", vce(cluster responseid)
est store A

	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("WI_GOP_Governor", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Experience", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
ysc(r(-10 15)) ylab(-10(5)15, labsize(vsmall))

graph save "4_figures/rbr_WI_GOP_Governor.gph", replace

** Four states need special attention because they do not include all three treatment dimensions (ideology, experience, money).

* Cases that need special attention -- NC GOP Senate
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe=="NC_GOP_Senate", vce(cluster responseid)
est store A

	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("NC_GOP_Senate", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
ysc(r(-10 15)) ylab(-10(5)15, labsize(vsmall))

graph save "4_figures/rbr_NC_GOP_Senate.gph", replace

* Cases that need special attention -- PA Dem Seante
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe=="PA_Dem_Senate", vce(cluster responseid)
est store A

	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("PA_Dem_Senate", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
ysc(r(-10 15)) ylab(-10(5)15, labsize(vsmall))

graph save "4_figures/rbr_PA_Dem_Senate.gph", replace

* Cases that need special attention -- PA GOP Seante
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced i.cand_name2 if race_fe=="PA_GOP_Senate", vce(cluster responseid)
est store A

	coefplot (A, msymbol(O) ciopts(lcolor(black)) color(black)), ///
	title("PA_GOP_Senate", size(small)) ///
	vertical ytitle("More Minus Less", size(small)) keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising", labsize(small)) graphregion(fcolor(white) ifcolor(white)) ///
ysc(r(-10 15)) ylab(-10(5)15, labsize(vsmall))

graph save "4_figures/rbr_PA_GOP_Senate.gph", replace

* Combine plots
fs "4_figures/rbr_*.gph"

local all_graphs ""
foreach file in `r(files)' {
    local all_graphs `"`all_graphs' "4_figures/`file'" "'
}

graph combine `all_graphs', graphregion(color(white))
graph export "4_figures/fig_si3.png", width(1000) replace


**# Figure SI4: Treatment Effects, by Trump Endorsements
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

gen moderation=t_moderate_y_+t_moderate_n_ // Variables convenient for yes/no contrasts
gen moneytreatment=t_money_y_ +t_money_n_
gen exper=t_exp_y_ +t_exp_n_

* Trump endorsements -- Most states
gen trump_endorse_race = .
replace trump_endorse_race = 1 if race_fe=="OH_GOP_Senate"
replace trump_endorse_race = 1 if race_fe=="PA_GOP_Senate"
replace trump_endorse_race = 1 if race_fe=="NC_GOP_Senate"
replace trump_endorse_race = 1 if race_fe=="WI_GOP_Governor"
replace trump_endorse_race = 0 if race_fe=="OH_GOP_Governor"

* For PA, endorsement came during fielding. Endorsement was 5/14/22.
gen startdate3 = substr(startdate, 1, 10)
gen startdate2 = date(startdate3, "YMD")
drop startdate3
order startdate2, after(startdate)
format startdate2 %td

replace trump_endorse_race = 0 if race_fe=="PA_GOP_Governor" & startdate2 < td(14may2022)
replace trump_endorse_race = 1 if race_fe=="PA_GOP_Governor" & startdate2 >= td(14may2022)

* By endorsements
reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe2 if trump_endorse_race == 0, vce(cluster responseid)
estimates store A

reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe2 if trump_endorse_race == 1, vce(cluster responseid)
estimates store B

coefplot (A, msymbol(O) ciopts(lcolor(green)) color(green)) ///
	(B, msymbol(D) ciopts(lcolor(blue)) color(blue)), ///
	title ("") vertical ytitle( "Differences between the two" "treatments (more versus less)") keep(t_moderate_y_ t_money_y_ t_exp_y_) yline(0) xlabel(1 "Moderate" 2 "Fundraising" 3 "Experience") legend(row(1) label(2 "No endorsement") label(4 "Endorsement")) graphregion(fcolor(white) ifcolor(white))
	
graph save "4_figures/endorsement_moderator.gph", replace

**# Table SI1: News Coverage for the Races Included in our sample
use "2_workingdata/News Article Content.dta", clear

** Drop Observations that are not relevant
drop if primary==0

** Limited to the 9 Races used in the Paper
	replace stateparty="PA-D" if stateparty=="PA-D "
gen electability_paper=1 if stateparty=="NC-R" & race=="US Senate" | ///
	stateparty=="OH-R" & race=="Gubernatorial" | ///
	stateparty=="OH-R" & race=="US Senate" | ///
	stateparty=="OH-D" & race=="US Senate" | ///
	stateparty=="PA-R" & race=="US Senate" | ///
	stateparty=="PA-R" & race=="Gubernatorial" | ///
	stateparty=="PA-D" & race=="US Senate" | ///
	stateparty=="WI-R" & race=="Gubernatorial" | ///
	stateparty=="WI-D" & race=="US Senate" 

keep if electability_paper==1

gen mention_ideology=ideology
	replace mention_ideology=1 if ideology==2
gen mention_fundraising=fundraising
	replace mention_fundraising=1 if fundraising==2
gen mention_experience=experience
	replace mention_experience=1 if experience==2

egen specificrace=concat(stateparty race)
tab specificrace mention_ideology, row
tab specificrace mention_fundraising, row
tab specificrace mention_experience, row

* Note: The Democratic and Republican Race averages reported at the bottom of Table SI1 were calculated manually. For instance, for the Democratic Race Average in Column 1:

di (63.2 + 44.1 + 34.1) / 3


**# Table SI3: Sample Demographics
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0 
bysort responseid: gen ingroup = _n
keep if ingroup==1

replace gender = 2 if gender==3 // Combine categories for simplicity.
tab gender state, col  nofreq

destring birthyr, replace
gen age = 2022 - birthyr
recode age (0/34 = 1) (35/54 = 2) (55 / 999 = 3), gen(age_bin)
lab def age_bin 1 "18" 2 "35" 3 "55"
lab val age_bin age_bin
tab age_bin state, col nofreq

gen white = 0
replace white = 1 if regexm(race,"White")
gen black = 0
replace black = 1 if regexm(race,"Black")
gen latino = 0
replace latino = 1 if regexm(race, "Latinx")
gen other = 0
replace other = 1 if regexm(race, "Asian") | regexm(race, "Alaska") | regexm(race, "Pacific") | regexm(race, "Other")

tab black state, col nofreq 
tab latino state, col nofreq
tab white state, col nofreq
tab other state, col nofreq

recode educ2 (6=7) // Collapsing graduate degree holders for simplicity.
tab educ2 state, col nofreq

recode pid (3 = 4), gen(pid_simple) // collapse "other" for simplicity
tab pid_simple
lab val pid_simple pid
tab pid_simple state, col nofreq

**# Table SI4: Voter Basline Knowledge, Sans Information
** Voters Only
use "2_workingdata/working_long.dta", clear
keep if control==1 & voter==1 & late_response==0
reg mc_office, vce(cluster responseid)
reg mc_money, vce(cluster responseid)
reg mc_moderate, vce(cluster responseid)

** All Respondents
use "2_workingdata/working_long.dta", clear
keep if control==1  & late_response==0
reg mc_office, vce(cluster responseid)
reg mc_money, vce(cluster responseid)
reg mc_moderate, vce(cluster responseid)

**# Table SI5: Vote for most electable?
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

egen e_max = max(electability_), by(responseid) // Mark most electable candidates
gen e_max_mark = 0
replace e_max_mark = 1 if electability_ == e_max

drop if e_max==. // Drop people who rated no candidates' electability

sort responseid 

gen vote_relevant = ""
replace vote_relevant = vote_sen_rep if regexm(race_fe, "Senate")
replace vote_relevant = vote_gov_rep if regexm(race_fe, "Governor") & vote_relevant==""
replace vote_relevant = vote_sen_dem if regexm(race_fe, "Senate") & vote_relevant==""

gen rowmark = 1 if cand_name==vote_relevant // look at vote from relevant race. Same as current candidate?
gen voted_formax = 1 if rowmark==1 & e_max_mark==1 // If you voted for the candidate whose Elect rating is in this row, was this candidate the most electable?
replace voted_formax = 0 if rowmark==1 & e_max_mark!=1 // If you voted for the candidate whose Elect rating is in this row, was someone else most electable?
egen votemax_spread = max(voted_formax), by(responseid)
bysort responseid: keep if _n==1 // keep one row per respondent

sort race_fe
tab race_fe votemax_spread if controlcond==1, row 

**# Table SI6: Spillover of Information Effects
use "2_workingdata/working_long.dta", clear
keep if voter==1 & late_response==0

reg perceived_office t_exp_y_ t_exp_n_ t_money_y_ t_money_n_ t_moderate_y_ t_moderate_n_ i.cand_name2, vce(cluster responseid)

reg perceived_money t_exp_y_ t_exp_n_ t_money_y_ t_money_n_ t_moderate_y_ t_moderate_n_ i.cand_name2, vce(cluster responseid)

reg perceived_moderate t_exp_y_ t_exp_n_ t_money_y_ t_money_n_ t_moderate_y_ t_moderate_n_ i.cand_name2, vce(cluster responseid)


**# Table SI7: Electability, Dropping WI Dems after July 28
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0
	drop if post_candrop==1

reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ i.cand_name2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0	
	
** All Voters
reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Democrats
	reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==1, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Republicans
	reg electability_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0

	
**# Table SI8: Instrumental Variable Analysis, Dropping WI Dems after July 28
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0
	drop if post_candrop==1
	
** All Voters, candidate FE
	xi: ivreg electability_ i.cand_name2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid)
	
** All Voters, race FE
	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid)
** Democrats, race FE
	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==1, cluster (responseid)
** Republicans, race FE
	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==2, cluster (responseid)

**# Table SI8: Vote Choice Analysis, Dropping WI Dems after July 28
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0
	drop if post_candrop==1
	
** All Voters, candidate FEs
	oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_  i.cand_name2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0

** All Voters, race FEs
	oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Democrats, race FEs
	oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==1, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0
	
** Republicans, race FEs
	oprobit postvote t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced  i.race_fe2 if party==2, vce(cluster responseid)
	test t_exp_y_ -t_exp_n = 0
	test t_money_y_ -t_money_n = 0
	test t_moderate_y_ -t_moderate_n = 0


**# Table SI10: Complier Treatment Effects on Electability, Retaining Wisconsin GOP Gubernatorial Primary
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0	
	
** Candidate fixed effects (pre-registered)
	xi: ivreg electability_ i.cand_name2 (perceived_moderate_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_exp_y_ t_exp_n_), cluster (responseid) 
	
** All Voters, race FEs
	xi: ivreg electability_ moderate experienced i.race_fe2 (perceived_moderate_  perceived_office_ = t_moderate_y_ t_moderate_n_ t_exp_y_ t_exp_n_), cluster (responseid)
** Democrats, race FEs
	xi: ivreg electability_ moderate experienced i.race_fe2 (perceived_moderate_  perceived_office_ = t_moderate_y_ t_moderate_n_ t_exp_y_ t_exp_n_) if party==1, cluster (responseid)
** Republicans, race FEs
	xi: ivreg electability_ moderate experienced i.race_fe2 (perceived_moderate_  perceived_office_ = t_moderate_y_ t_moderate_n_ t_exp_y_ t_exp_n_) if party==2, cluster (responseid)
	
**# Table SI11: First Stage Estimates for Complier Treatment Effects 
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0

gen samp = .

** 11a: All voters, candidate FEs.
xi: ivreg electability_ i.cand_name2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid) first

replace samp = e(sample)

reg perceived_moderate_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ i.cand_name2 if samp==1

reg perceived_money_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_  i.cand_name2 if samp==1

reg perceived_office_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ i.cand_name2 if samp==1

** 11b: All Voters, race FEs
	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_), cluster (responseid) first
	
replace samp = e(sample)
	
reg perceived_moderate_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1

reg perceived_money_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_  moderate money experienced i.race_fe2 if samp==1

reg perceived_office_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1
	
** 11c: Democrats, race FEs
	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==1, cluster (responseid) first

replace samp = e(sample)
	
reg perceived_moderate_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1

reg perceived_money_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_  moderate money experienced i.race_fe2 if samp==1

reg perceived_office_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1

** 11d: Republicans, race FEs

	xi: ivreg electability_ moderate money experienced i.race_fe2 (perceived_moderate_ perceived_money_ perceived_office_ = t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_) if party==2, cluster (responseid) first

replace samp = e(sample)
	
reg perceived_moderate_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1

reg perceived_money_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_  moderate money experienced i.race_fe2 if samp==1

reg perceived_office_ t_moderate_y_ t_moderate_n_ t_money_y_ t_money_n_ t_exp_y_ t_exp_n_ moderate money experienced i.race_fe2 if samp==1

**# Table SI12: Correlations among candidate attributes
import delimited "2_workingdata/cand_attributes.csv", varnames(1) encoding(UTF-8) clear

corr moderate money office

**# Table SI13: Partisan Contrasts in Treatment Effects
use "2_workingdata/working_long.dta", clear
	keep if voter==1 & late_response==0

gen moderation=t_moderate_y_+t_moderate_n_ // Variables convenient for yes/no contrasts
gen moneytreatment=t_money_y_ +t_money_n_
gen exper=t_exp_y_ +t_exp_n_	
	
gen race_fe3 = race_fe2 // Dems and Reps need an excluded category with a common name.
replace race_fe3 = 1 if race_fe=="NC_GOP_Senate"
replace race_fe3 = 1 if race_fe=="OH_Dem_Senate"

reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe3  if party==1

est store Dem

reg electability_ t_moderate_y_ moderation t_money_y_ moneytreatment t_exp_y_ exper moderate money experienced  i.race_fe3  if party==2

est store Rep

suest Dem Rep, vce(cluster responseid)

* In-text statistics.
test [Dem_mean]t_moderate_y_ = [Rep_mean]t_moderate_y_
test [Dem_mean]t_money_y_ = [Rep_mean]t_money_y_
test [Dem_mean]t_exp_y_ = [Rep_mean]t_exp_y_


